<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../引入vue2.js"></script>
</head>

<body>
    <div id="app">
        <input type="text" v-model="uname">
        <div>双向数据绑定--{{uname}}</div>
        <button @click="add">add</button>
        <ul>
            <li v-for="(item,index) in list">
                {{item}}
                <button @click="del(index)">del</button>
            </li>
        </ul>

        <div v-if="list.length==0">无待办事项</div>
    </div>
</body>

<script>
    let vm = new Vue({
        el: '#app',
        data: {
            list: ['a', 'b', 'c', 'd'],
            uname: ''
        },
        methods: {
            add() {
                console.log('add', this.uname);
                this.list.push(this.uname);
                // 清空
                this.uname = '';
            },
            del(index) {
                console.log('del', index);
                this.list.splice(index, 1);
            }
        }
    });
</script>

</html>